<?php 
/* cache php just takes a requested image, opens 
 * it and adds caching headers for it */
require_once("config.php");

/* output gzip enable, when gzip is accepted */
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')){
	// client accepts gzip, so gzip the content
	ob_start("ob_gzhandler");
}else{ 
	// continue normally when gzip is unsupported
	ob_start();
}

// get the local filename of the requested file
$filename = CONFIG_ROOTDIR."/".$_GET["p"]."/".$_GET["f"];

// set the expires header to enforce caching
header("Cache-Control: max-age=604800");
header('Date: '.gmdate('D, d M Y H:i:s \G\M\T', time()));
header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', time()));
header("Expires: ".gmdate('D, d M Y H:i:s \G\M\T',(time()+604800)));
				
// output the result
$ext = strtolower(substr($filename, strrpos($filename, ".")+1));
header("Content-Type: image/".$ext);
echo file_get_contents($filename);
?>